unit UserLocate;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TEMPLETFORM, HemisphereButton, ComCtrls, StdCtrls, ExtCtrls,
  Menus, ToolWin, ModalForm, MoveImageButton, LabelButton;

type
  TUserLocateForm = class(TMyModalForm)
    rg: TRadioGroup;
    rb1: TGroupBox;
    Edit1: TEdit;
    rb2: TGroupBox;
    ComboBox1: TComboBox;
    Edit2: TEdit;
    ComboBox2: TComboBox;
    ComboBox3: TComboBox;
    Edit3: TEdit;
    rb3: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    dtpStart: TDateTimePicker;
    dtpEnd: TDateTimePicker;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure rgClick(Sender: TObject);
    procedure Edit2KeyPress(Sender: TObject; var Key: Char);
    procedure FormShow(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure MIBtnOKClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  UserLocateForm: TUserLocateForm;

implementation

uses data;

{$R *.dfm}

procedure TUserLocateForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  Action:=caFree;
end;

procedure TUserLocateForm.rgClick(Sender: TObject);
begin
  inherited;
  if rg.ItemIndex =3 then
    rb3.Visible :=true
  else begin
    rb3.Visible :=false;
    if rg.ItemIndex >=4 then
      rb2.Visible :=true
    else
      rb2.Visible :=false;
  end;
end;

procedure TUserLocateForm.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
  inherited;
  if not(Key in ['0'..'9',#8,#13]) then
    begin
      Key:=#0;
      Beep;
    end;
end;

procedure TUserLocateForm.FormShow(Sender: TObject);
begin
  inherited;
  dtpStart.DateTime:=now;
  dtpEnd.DateTime :=now;
end;

procedure TUserLocateForm.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  inherited;
  if Key=#13 then
    MIBtnOKClick(MIBtnOK);
end;

procedure TUserLocateForm.MIBtnOKClick(Sender: TObject);
var
  strWhere:string;
  strOrder:string;
begin
  inherited;
  case rg.ItemIndex of
  0:  begin
        strWhere:='Where stuNo='+''''+trim(Edit1.Text)+'''';
        strOrder:='order by stuNo';
      end;
  1:  begin
        strWhere:='Where stuName like '+''''+'%'+Trim(edit1.Text)+'%'+'''';
        strOrder:='order by stuName';
      end;
  2:  begin
        strWhere:='Where stuClass like '+''''+'%'+Trim(edit1.Text)+'%'+'''';
        strOrder:='order by stuClass';
      end;
  3:  begin
        strWhere:='Where stuLoginDate between #'+DateToStr(dtpStart.Date)
          +'# and #'+DateToStr(dtpEnd.Date)+'#';
        strOrder:='order by stuLoginDate';
      end;
  4:  begin
        if Trim(Edit2.Text)='' then Edit2.Text :='0';
        if Trim(Edit3.Text)='' then Edit3.Text :='0';
        strWhere:='Where stuPrepTime'+combobox1.Text +Trim(edit2.Text);
        if Trim(Combobox2.Text) <>'' then
          strWhere:=strWhere+' '+combobox2.Text +' stuPrepTime'+combobox3.Text +edit3.Text;
        strOrder:='order by stuPrepTime';
      end;
  5:  begin
        if Trim(Edit2.Text)='' then Edit2.Text :='0';
        if Trim(Edit3.Text)='' then Edit3.Text :='0';
        strWhere:='Where stuAllUsedTime'+combobox1.Text +Trim(edit2.Text);
        if Trim(Combobox2.Text) <>'' then
          strWhere:=strWhere+' '+combobox2.Text +' stuAllUsedTime'+combobox3.Text +edit3.Text;
        strOrder:='order by stuAllUsedTime';
      end;
  end;
  with DM.ADOQMember do
  begin
    Active:=false;
    SQL.Strings[4]:=strWhere;
    SQL.Strings[5]:=strOrder;
    Filtered :=false;
    Active:=true;
    ModalResult:=mrOK;
  end;
end;
end.
